package com.xpgk.mvc.productOrgExperience;

import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.xpgk.dto.RenderBean;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.productSet.Product;
import com.xpgk.mvc.productSet.ProductExperience;
import com.xpgk.mvc.productSet.ProductSetService;
import com.xpgk.mvc.productSet.ProductValidator;

public class ProductOrgExperienceController extends BaseController{
	private ProductOrgExperienceService productOrgExperienceService;
	
	public void index() {
		setAttr("organIds", getCUserOrganIds());
		render("productOrgExperience.html");
	}
	
	/**
	 * 产品列表
	 */
	public void productList(){
		String json = paging(splitPage, ProductOrgExperience.sqlId_splitPageSelect, ProductOrgExperience.sqlId_splitPageFrom);
		renderJson(json);
	}
	
	/**
	 * 跳转至添加产品
	 */
	public void toAddProduct(){
		String productIds = getPara("productIds");
		String sql = "SELECT * FROM sb_product where ids = ?";
		Product product =Product.dao.findFirst(sql,productIds);
		setAttr("product", product);
		render("addProductExp.html");
	}
	
	/**
	 * 添加产品
	 */
	
	public void addProduct(){
		ProductOrgExperience pes = getModel(ProductOrgExperience.class);
		
		RenderBean renderBean = productOrgExperienceService.addProduct(pes,getCUserIds(),getCUserOrganIds());
		renderJson(renderBean);
	}
	
	/**
	 * 跳转至编辑
	 */
	public void toUpProduct(){
		String ids = getPara("ids");
		
		ProductOrgExperience productOrgExperience = ProductOrgExperience.dao.findById(ids);
		
		setAttr("productOrgExperience",productOrgExperience);
		render("upProductExp.html");
	}
	
	/**
	 * 编辑
	 */
	
	public void upProduct(){
		
		ProductOrgExperience pes = getModel(ProductOrgExperience.class);
		
		RenderBean renderBean = productOrgExperienceService.upProduct(pes,getCUserIds(),getCUserOrganIds());
		renderJson(renderBean);
		
	
	}
	
	
	/*
	 * 更该产品状态
	 */
	
	public void productListstruts(){
		String ids = getPara("ids");

		
		ProductOrgExperience productOrgExperience = ProductOrgExperience.dao.findById(ids);
		
		productOrgExperience.set(ProductOrgExperience.column_dataStatus,"0");
		boolean result = productOrgExperience.update();
		renderJson(result);
	}

}
